package ru.paswd.marketprice.ui.components

import android.content.Context
import androidx.core.content.ContextCompat
import ru.paswd.marketprice.R

class PricePointColor(private val rangeMin: Int, private val rangeMax: Int) {

    fun getColor(context: Context, price: Int): Int {
        val minColor = ContextCompat.getColor(context, R.color.shop_price_min)
        val maxColor = ContextCompat.getColor(context, R.color.shop_price_max)
        val midColor = ContextCompat.getColor(context, R.color.shop_price_middle)

        val diffRange = rangeMax - rangeMin
        val diffCurr = price - rangeMin

        if (diffCurr.toFloat() > diffRange.toFloat() / 3f * 2f) {
            return maxColor
        }

        if (diffCurr.toFloat() > diffRange.toFloat() / 3f) {
            return midColor
        }

        return minColor
    }
}